#include "idt.h"

// 定义idt和idt寄存器
static idt_gate_t idt[IDT_ENTRY_NUM];
static idt_register_t idt_reg;

void set_idt_gate(int n, uint32_t handler) {
    idt[n].offset_low = (uint16_t) (handler & 0xffff);
    idt[n].segment_selector = KERNEL_SEGMENT_SELECTOR;
    idt[n].always0 = 0;
    idt[n].flags = IDT_GATE_FLAG;
    idt[n].offset_high = (uint16_t) (handler >> 16);
}

void set_idt() {
    idt_reg.limit = sizeof(idt_gate_t) * IDT_ENTRY_NUM - 1;
    idt_reg.address = (uint32_t) &idt;
    asm volatile("lidtl (%0)" : : "r" (&idt_reg));
}
